﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PongTeam
{
    public class Sprite
    {
        private float _rapportWidth;
        private float _rapportHeight;

        private int _screenHeight;
        private int _screenWidth;


        public Texture2D Texture
        {
            get { return _texture; }
            set { _texture = value; }
        }
        private Texture2D _texture;

        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }
        private Vector2 _position;

        public Vector2 Direction
        {
            get { return _direction; }
            set { _direction = Vector2.Normalize(value); }
        }
        private Vector2 _direction;

        public float Speed
        {
            get { return _speed; }
            set { _speed = value; }
        }
        private float _speed;

        public virtual void Initialize(int screenWidth, int screenHeight)
        {
            _rapportWidth = screenWidth / 1920.0f;
            _rapportHeight = screenHeight / (screenHeight / (float)screenWidth * 1920.0f);
            _screenHeight = screenWidth;
            _screenWidth = screenHeight;
            _position = Vector2.Zero;
            _direction = Vector2.Zero;
            _speed = 0;
        }

        public virtual void LoadContent(ContentManager content, string assetName)
        {
            _texture = content.Load<Texture2D>(assetName);
        }

        public virtual void Update(GameTime gameTime)
        {
            _position += _direction * _speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
        }


        public virtual void Draw(SpriteBatch spriteBatch, GameTime gameTime,int valeur)
        {
            if(valeur == 2)
                spriteBatch.Draw(_texture, new Rectangle((int)(_position.X),(int)( _position.Y),(int)(Texture.Width * _rapportWidth ),(int)(Texture.Height * _rapportHeight)),new Rectangle(0,0,Texture.Width, Texture.Height), Color.White);
            else
                spriteBatch.Draw(_texture, new Rectangle(0, 0, _screenHeight, _screenWidth), Color.White);
        }
    }
}